//
// Created by Wirano on 2020/11/9.
//

#ifndef ANO_PORT_ANO_FCDATA_H
#define ANO_PORT_ANO_FCDATA_H
/* Includes ------------------------------------------------------------------*/
#include "config.h"
/* Exported types ------------------------------------------------------------*/
#define TRUE 1
#define FALSE 0

enum
{
	AUTO_TAKE_OFF_NULL = 0,
	AUTO_TAKE_OFF = 1,
	AUTO_TAKE_OFF_FINISH,
	AUTO_LAND,
};

enum pwminmode_e
{
	PWM = 0,
	PPM,
	SBUS,
};

enum
{
 A_X = 0,
 A_Y ,
 A_Z ,
 G_X ,
 G_Y ,
 G_Z ,
 TEM ,
 MPU_ITEMS ,
};


enum
{
 CH_ROL = 0,
 CH_PIT ,
 CH_THR ,
 CH_YAW ,
 AUX1 ,
 AUX2 ,
 AUX3 ,
 AUX4 ,
 CH_NUM,//8
};

enum
{
	m1=0,
	m2,
	m3,
	m4,
	m5,
	m6,
	m7,
	m8,

};

enum
{
	MPU_6050_0 = 0,
	MPU_6050_1,

};

enum
{
	X = 0,
	Y = 1,
	Z = 2,
	VEC_XYZ,
};

enum
{
	ROL = 0,
	PIT = 1,
	YAW = 2,
	VEC_RPY,
};

enum
{
	KP = 0,
	KI = 1,
	KD = 2,
	PID,
};

enum _power_alarm
{

	HIGH_POWER = 0,
	HALF_POWER,
	LOW_POWER ,
	LOWEST_POWER,


};


enum _flight_mode
{
	ATT_STAB = 0,//Attitude stabilization
	LOC_HOLD,
	RETURN_HOME,

};

//thr_mode
enum
{
  THR_MANUAL = 0,
	THR_AUTO,

};

typedef struct
{
	uint8_t first_f;
	float acc_offset[VEC_XYZ];
	float gyro_offset[VEC_XYZ];

	float surface_vec[VEC_XYZ];

	float mag_offset[VEC_XYZ];
	float mag_gain[VEC_XYZ];

} _save_st ;
extern _save_st save;

typedef struct
{
	//基本状态/传感器
	uint8_t start_ok;
	uint8_t sensor_imu_ok;
	uint8_t mems_temperature_ok;

	uint8_t motionless;
	uint8_t power_state;
	uint8_t wifi_ch_en;
	uint8_t chn_failsafe;
	uint8_t rc_loss;
	uint8_t rc_loss_back_home;
	uint8_t gps_ok;


	//控制状态
	uint8_t manual_locked;
	uint8_t unlock_err;
	uint8_t unlock_cmd;//解锁命令
	uint8_t unlock_sta;//解锁标志位
	uint8_t thr_low;
	uint8_t locking;
	uint8_t taking_off; //起飞
	uint8_t set_yaw;
	uint8_t ct_loc_hold;
	uint8_t ct_alt_hold;


	//飞行状态
	uint8_t flying;
	uint8_t auto_take_off_land;
	uint8_t home_location_ok;
	uint8_t speed_mode;
	uint8_t thr_mode;
	uint8_t flight_mode;
	uint8_t flight_mode2;
	uint8_t gps_mode_en;
	uint8_t motor_preparation;
	uint8_t locked_rotor;


}_flag;
extern _flag flag;

typedef struct
{
	float vel_limit_xy;
	float vel_limit_z_p;
	float vel_limit_z_n;
	float yaw_pal_limit;
}_fc_sta_var_st; //state variable
extern _fc_sta_var_st fc_stv;

typedef struct
{
	uint8_t sonar_on;
	uint8_t tof_on;
	uint8_t of_flow_on;
	uint8_t of_tof_on;
	uint8_t baro_on;
	uint8_t gps_on;
	uint8_t uwb_on;
	uint8_t opmv_on;

    //新加的
    uint8_t t265_on;


}_switch_st;//还是不要动为好
extern _switch_st switchs;

typedef struct
{
	uint8_t gyro_ok;
	uint8_t acc_ok;
	uint8_t mag_ok;
	uint8_t baro_ok;
	uint8_t gps_ok;
	uint8_t sonar_ok;
	uint8_t tof_ok;
	uint8_t of_ok;//没用
	uint8_t of_df_ok;//没用

    //自己加的
    uint8_t t265_ok;

} _sensor_hd_check_st; //Hardware
extern _sensor_hd_check_st sens_hd_check;
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */

void data_save(void);
void Para_Data_Init(void);

#endif //ANO_PORT_ANO_FCDATA_H
